{% extends "base.html" %}

{% block body %}
    <h1> 设置modbus server 地址空间 </h1>
    <form>
        modbus_server_uuid:: <input type="text" name="uuid" id="uuid"><br>
        modbus_server_host: <input type="text" name="host" id="host"><br>
        modbus_server_port: <input type="text" name="port" id="port"><br>
        modbus_server_slave: <input type="text" name="slave_id" id="slave_id"><br>
        <hr>
        <input type="checkbox" name="coils" id="coils" value="1"> COILS <br>
        start_address:: <input type="text" name="start_address_1" id="start_address_1"><br>
        quantity_of_tag:: <input type="text" name="quantity_1" id="quantity_1"><br>
        <hr>
        <input type="checkbox" name="discrete_inputs" id="discrete_inputs" value="2"> DISCRETE_INPUTS <br>
        start_address:: <input type="text" name="start_address_2" id="start_address_2"><br>
        quantity_of_tag:: <input type="text" name="quantity_2" id="quantity_2"><br>
        <hr>
        <input type="checkbox" name="hoding_register" id="hoding_register" value="3"> HOLDING_REGISTERS <br>
        start_address:: <input type="text" name="start_address_3" id="start_address_3"><br>
        quantity_of_tag:: <input type="text" name="quantity_3" id="quantity_3"><br>
        <hr>
        <input type="checkbox" name="analog_inputs" id="analog_inputs" value="4"> ANALOG_INPUTS <br>
        start_address:: <input type="text" name="start_address_4" id="start_address_4"><br>
        quantity_of_tag:: <input type="text" name="quantity_4" id="quantity_4"><br>
        <hr>
        <input type="button" value="提交" id="submit">
    </form>
{% endblock %}

{% block script %}
    <script type="application/javascript">
        $(document).ready(function () {
            $('#submit').click(function () {
                $.ajax(
                    {
                        type: 'POST',
                        url: '/add_server',
                        data: {
                            uuid: $('#uuid').val(),
                            host: $('#host').val(),
                            port: $('#port').val(),
                            slave_id: $('#slave_id').val(),
                            coils: $('#coils').is(":checked"),
                            start_address_1: $('#start_address_1').val(),
                            quantity_1: $('#quantity_1').val(),
                            discrete_inputs: $('#discrete_inputs').is(":checked"),
                            start_address_2: $('#start_address_2').val(),
                            quantity_2: $('#quantity_2').val(),
                            hoding_register: $('#hoding_register').is(":checked"),
                            start_address_3: $('#start_address_3').val(),
                            quantity_3: $('#quantity_3').val(),
                            analog_inputs: $('#analog_inputs').is(":checked"),
                            start_address_4: $('#start_address_4').val(),
                            quantity_4: $('#quantity_4').val(),
                        },
                        dataType: 'json',
                        success: function (resp) {
                            console.log(resp);
                        },
                        error: function(err) {
                            console.log(err);
                        }
                    }
                );
            });
        });

    </script>
{% endblock %}